package com.dems.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dems.dao.dataobject.CfgAlarmMessage;
import com.dems.dao.dataobject.User;
import com.dems.dao.mapper.la.CfgAlarmMessageMapper;
import com.dems.domain.AlarmMessageReqVO;
import com.dems.domain.alarm.AlarmMessageDto;
import com.dems.service.AlarmMessageService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AlarmMessageServiceImpl implements AlarmMessageService {
    @Autowired
    private CfgAlarmMessageMapper cfgAlarmMessageMapper;

    @Override
    public Page selectByPage(AlarmMessageReqVO reqVO) {
        Page page = new Page(reqVO.getPageNum(), reqVO.getPageSize());
        CfgAlarmMessage cfgAlarmMessage = new CfgAlarmMessage();
        BeanUtils.copyProperties(reqVO, cfgAlarmMessage);
        return cfgAlarmMessageMapper.queryByPage(page, cfgAlarmMessage);
    }

    @Override
    public int confirmAlarm(AlarmMessageDto alarmMessageDto, User user) {
        CfgAlarmMessage cfgAlarmMessage = new CfgAlarmMessage();
        BeanUtils.copyProperties(alarmMessageDto, cfgAlarmMessage);
        cfgAlarmMessage.setConfirmTime(new Date());
        cfgAlarmMessage.setConfirmBy(user.getName());
        cfgAlarmMessage.setConfirmUserId(user.getUserId());
        return cfgAlarmMessageMapper.updateByPrimaryKeySelective(cfgAlarmMessage);
    }
}
